<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>代码分析工具</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/element-plus@2.3.6/dist/index.css" />
  <style>
    body {
      font-family: 'Microsoft YaHei', sans-serif;
      margin: 0;
      padding: 0;
      background-color: #f5f7fa;
    }
    #app {
      max-width: 1200px;
      margin: 0 auto;
      padding: 20px;
    }
    .header {
      text-align: center;
      margin-bottom: 30px;
    }
    .header h1 {
      color: #409EFF;
      margin-bottom: 10px;
    }
    .main-content {
      background-color: #fff;
      border-radius: 8px;
      box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
      padding: 20px;
    }
    .upload-container {
      text-align: center;
      padding: 20px 0;
    }
    .step-container {
      margin-top: 20px;
    }
    .file-list {
      margin-top: 20px;
      max-height: 300px;
      overflow-y: auto;
      border: 1px solid #e6e6e6;
      border-radius: 4px;
      padding: 10px;
    }
    .module-card {
      margin-bottom: 15px;
    }
    .tree-view {
      font-family: 'Courier New', monospace;
      white-space: pre;
      padding: 10px;
      background-color: #f8f8f8;
      border-radius: 4px;
      overflow-x: auto;
      max-height: 500px;
      overflow-y: auto;
    }
    .tab-container {
      margin-top: 20px;
    }
  </style>
</head>
<body>
  <div id="app">
    <div class="header">
      <h1>压缩包提取主要功能文件工具</h1>
      <p>上传压缩包，提取并分析主要功能代码</p>
    </div>
    
    <div class="main-content">
      <el-steps :active="activeStep" align-center>
        <el-step title="上传压缩包" description="支持多种格式"></el-step>
        <el-step title="AI模型分析" description="选择AI模型并分析"></el-step>
        <el-step title="查看结果" description="功能模块分类"></el-step>
      </el-steps>
      
      <div class="step-container">
        <!-- 步骤1：上传压缩包 -->
        <div v-if="activeStep === 0" class="upload-container">
          <el-upload
            :action="uploadUrl"
            :on-success="handleUploadSuccess"
            :on-error="handleUploadError"
            :before-upload="beforeUpload"
            :limit="1"
            drag
          >
            <el-icon class="el-icon--upload"><upload-filled /></el-icon>
            <div class="el-upload__text">
              拖拽文件到这里或 <em>点击上传</em>
            </div>
            <template #tip>
              <div class="el-upload__tip">
                支持的文件类型: .zip, .rar, .7z, .tar, .gz
              </div>
            </template>
          </el-upload>
          
          <div v-if="uploadStatus.success" style="margin-top: 20px; text-align: left;">
            <el-alert
              title="上传成功"
              type="success"
              :closable="false"
              show-icon
            >
              <template #default>
                <p>任务ID: {{ taskId }}</p>
                <p>共提取到 {{ fileTree.length }} 个文件</p>
              </template>
            </el-alert>
            
            <div class="tab-container">
              <el-tabs type="border-card">
                <el-tab-pane label="文件树视图">
                  <div class="tree-view" v-if="treeText">
                    {{ treeText }}
                  </div>
                </el-tab-pane>
                <el-tab-pane label="节点树视图">
                  <div class="file-list" v-if="fileTree.length > 0">
                    <el-tree
                      :data="formatFileTree(fileTree)"
                      :props="{ label: 'label', children: 'children' }"
                      default-expand-all
                    ></el-tree>
                  </div>
                </el-tab-pane>
              </el-tabs>
            </div>
            
            <el-button type="primary" @click="activeStep++" style="margin-top: 20px;">
              继续
            </el-button>
          </div>
          
          <el-alert
            v-if="uploadStatus.error"
            :title="uploadStatus.message"
            type="error"
            show-icon
            style="margin-top: 20px;"
          ></el-alert>
        </div>
        
        <!-- 步骤2：选择AI模型并分析 -->
        <div v-if="activeStep === 1">
          <el-card>
            <template #header>
              <div class="card-header">
                <span>选择AI分析模型</span>
              </div>
            </template>
            
            <el-radio-group v-model="selectedModel">
              <el-radio v-for="model in models" :key="model.id" :label="model.id">
                {{ model.name }}
              </el-radio>
            </el-radio-group>
            
            <div style="margin-top: 20px; text-align: center;">
              <el-button type="primary" @click="analyzeFiles" :loading="analyzing">
                开始分析
              </el-button>
            </div>
          </el-card>
          
          <el-alert
            v-if="analyzeStatus.error"
            :title="analyzeStatus.message"
            type="error"
            show-icon
            style="margin-top: 20px;"
          ></el-alert>
        </div>
        
        <!-- 步骤3：查看结果 -->
        <div v-if="activeStep === 2">
          <el-card>
            <template #header>
              <div class="card-header">
                <span>分析结果</span>
                <el-button 
                  type="primary" 
                  link 
                  @click="downloadAllFiles"
                >
                  下载全部合并文件
                </el-button>
              </div>
            </template>
            
            <div v-if="modules.length === 0">
              <el-empty description="暂无数据"></el-empty>
            </div>
            
            <div v-for="(module, index) in modules" :key="index" class="module-card">
              <el-card>
                <template #header>
                  <div class="card-header">
                    <span>{{ module.name }}</span>
                    <el-button 
                      type="primary" 
                      link
                      @click="downloadModuleFiles(module.name)"
                    >
                      下载模块文件
                    </el-button>
                  </div>
                </template>
                
                <el-collapse>
                  <el-collapse-item title="查看文件列表">
                    <el-tree
                      :data="formatModuleFiles(module.files)"
                      :props="{ label: 'label', children: 'children' }"
                    ></el-tree>
                  </el-collapse-item>
                </el-collapse>
              </el-card>
            </div>
          </el-card>
        </div>
      </div>
    </div>
  </div>
  
  <script src="https://cdn.jsdelivr.net/npm/vue@3.2.47/dist/vue.global.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/element-plus@2.3.6/dist/index.full.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/@element-plus/icons-vue"></script>
  <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
  <script src="js/app.js"></script>
</body>
</html> 